package com.example.myapp_1.worker;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

import java.util.Calendar;

import com.example.myapp_1.util.MediaUtil;

public class PeriodicWorker extends Worker {

    public PeriodicWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
    }

    @NonNull
    @Override
    public Result doWork() {
        Log.d("PeriodicWorker", "=== === === doWork() === === === 111");

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        int hour = calendar.get(Calendar.HOUR_OF_DAY); // 0-23
        if (hour < 6)
            return Result.failure();

        Log.d("PeriodicWorker", "=== === === doWork() === === === 222");

        MediaUtil.changeVolume(getApplicationContext());
        return Result.success();
    }

}
